package com.homeparking.manage.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.homeparking.common.annotation.Log;
import com.homeparking.common.core.controller.BaseController;
import com.homeparking.common.core.domain.AjaxResult;
import com.homeparking.common.enums.BusinessType;
import com.homeparking.manage.domain.ManageRecord;
import com.homeparking.manage.service.IManageRecordService;
import com.homeparking.common.utils.poi.ExcelUtil;
import com.homeparking.common.core.page.TableDataInfo;

/**
 * 备案订单Controller
 * 
 * @author liuyangyang
 * @date 2025-05-04
 */
@RestController
@RequestMapping("/manage/record")
public class ManageRecordController extends BaseController
{
    @Autowired
    private IManageRecordService manageRecordService;

    /**
     * 查询备案订单列表
     */
    @PreAuthorize("@ss.hasPermi('manage:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ManageRecord manageRecord)
    {
        startPage();
        List<ManageRecord> list = manageRecordService.selectManageRecordList(manageRecord);
        return getDataTable(list);
    }

    /**
     * 拉取备案订单
     */

    @PostMapping("/pull")
    public AjaxResult pullRecord(@RequestBody List <ManageRecord> manageRecord)
    {
        return toAjax(manageRecordService.pullManageRecord(manageRecord));
    }

    /**
     * 拉取备案订单
     */

    @GetMapping("/count/everyday")
    public AjaxResult countEveryday(@RequestParam("startTime") String startTime,
                                    @RequestParam("endTime") String endTime)
    {

        List<Map<String, Object>> result = manageRecordService.countEveryday(startTime,endTime);

        return AjaxResult.success(result);
    }

    /**
     * 导出备案订单列表
     */
    @PreAuthorize("@ss.hasPermi('manage:record:export')")
    @Log(title = "备案订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManageRecord manageRecord)
    {
        List<ManageRecord> list = manageRecordService.selectManageRecordList(manageRecord);
        ExcelUtil<ManageRecord> util = new ExcelUtil<ManageRecord>(ManageRecord.class);
        util.exportExcel(response, list, "备案订单数据");
    }

    /**
     * 获取备案订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") String recordId)
    {
        return success(manageRecordService.selectManageRecordByRecordId(recordId));
    }

    /**
     * 新增备案订单
     */
    @PreAuthorize("@ss.hasPermi('manage:record:add')")
    @Log(title = "备案订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageRecord manageRecord)
    {
        return toAjax(manageRecordService.insertManageRecord(manageRecord));
    }

    /**
     * 修改备案订单
     */
    @PreAuthorize("@ss.hasPermi('manage:record:edit')")
    @Log(title = "备案订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageRecord manageRecord)
    {
        return toAjax(manageRecordService.updateManageRecord(manageRecord));
    }

    /**
     * 删除备案订单
     */
    @PreAuthorize("@ss.hasPermi('manage:record:remove')")
    @Log(title = "备案订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable String[] recordIds)
    {
        return toAjax(manageRecordService.deleteManageRecordByRecordIds(recordIds));
    }
}
